import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  // 全局状态数据
  state: {
    token: ''
  },
  actions: {
    setToken({ commit }, token) {
      // 存储token到sessionStorage中
      sessionStorage.setItem('token', token)
      commit('setToken', token)
    }
  },
  mutations: {
    setToken(state, token) {
      state.token = token
    }
  }
})
